/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BUS;

import DAO.DauSachDAO;
import Entity.DauSach;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class DauSachImpl implements DauSachBUS {

    private DauSachDAO dao;
    
    public DauSachImpl() {
        dao = new DAO.DauSachImpl();
    }
    
    public boolean add(DauSach data) {
        if (data.getTenSach().isEmpty()) 
            return false;
        
        return dao.add(data);
    }    

    public ArrayList getAll() {
        ResultSet rs = dao.getAll();
        ArrayList list = new ArrayList();
        DauSach data;
        try {
            while (rs.next()) {
                data = new DauSach(rs.getInt(1), rs.getInt(2), rs.getInt(3), 
                        rs.getInt(4), rs.getString(5));
                list.add(data);
            }            
        } catch (SQLException ex) {
            Logger.getLogger(DauSachImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }
}
